app.controller("consultationController",function ($scope,$controller,consultationService) {

    //继承baseController
    $controller('baseController',{$scope:$scope});

    $scope.searchEntity = {};

    //查询留言记录
    $scope.findPage = function (pageNum,pageSize) {

        if (pageNum == null) pageNum = 1;

        if (pageSize == null) pageSize = 10;

        if (startTime != null) $scope.searchEntity.startTime = startTime;

        if (endTime != null) $scope.searchEntity = endTime;

        consultationService.findPage(pageNum,pageSize,$scope.searchEntity).success(function (response) {

            if (response.code == 200) {

                //获取留言记录
                $scope.consultationList = response.data;

                //更新总记录数
                $scope.paginationConf.totalItems=response.total;

            }else {
                alert(response.msg)
            }
        })

    };

    //重置条件查询参数
    $scope.resetSearchEntity = function () {

        $scope.searchEntity = {};

        $scope.reloadList();
    };

    //监听是否处理字段
    $scope.$watch("searchEntity.isHandle",function (newValue, oldValue) {

        if (newValue == null) return;

        $scope.reloadList();
    });

    //修改留言状态
    $scope.updateIsHandle = function (isHandle,index) {

        if (index != null){
            $scope.selectIds = [];

            $scope.selectIds.push(index);
        }

        consultationService.updateIsHandle(isHandle,$scope.selectIds).success(function (response) {

            if (response.code == 200){

                $scope.reloadList();

                $scope.selectIds = [];

            } else {
                alert(response.msg);
            }
        })
    }
});